package net;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;

/**
 * 把收信息功能写到线程里
 */
public class Receiver extends  Thread{
    private Socket socket;
    private String name;

    public Receiver(Socket socket, String name) {
        this.socket = socket;
        this.name = name;
    }

    @Override
    public void run() {
        try {
            InputStreamReader isr=new InputStreamReader(socket.getInputStream());
            BufferedReader br=new BufferedReader(isr);
            String s=br.readLine();
            while (!s.equals("bye")){
                System.out.println(name +"说："+s);
                s=br.readLine();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}




